package com.syaccp.controller;


import cn.hutool.core.util.ObjectUtil;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.syaccp.model.Detail;
import com.syaccp.service.DetailService;
import com.syaccp.utils.Result;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;

@RestController
@RequestMapping("/api/detail")
public class DetailController {
   @Autowired
   private DetailService  detailService;

    @GetMapping("/st")
    public Result<Map<String, Long>> list(@RequestParam String zpshName){
        QueryWrapper<Detail> queryWrapper = new QueryWrapper<>();
        queryWrapper.select(" zpsh_name as zpshName,count(*) as number");
        queryWrapper.eq(ObjectUtil.isNotEmpty(zpshName),"zpsh_name",zpshName);
        List<Map<String, Object>> listMaps =detailService.listMaps(queryWrapper);
        Map<String, Long> subNodeAmountMap = listMaps.stream().collect(Collectors.toMap(e-> (String) e.get("zpshName"), e-> (Long) e.get("number")));
        return Result.success(subNodeAmountMap);
    }
    //查询全部
    @GetMapping("/all")
    public Result<List<Detail>> all(){
        System.out.println("9999");
        LambdaQueryWrapper<Detail> lambdaQueryWrapper = new LambdaQueryWrapper<>();
        List<Detail> list = detailService.list(lambdaQueryWrapper);
        return Result.success(list);
    }
    @GetMapping("/list")
    public Result<List<Detail>> list() {
        return Result.success(detailService.pageC());
    }
    @GetMapping("/Term")
    public Result<List<Detail>> Term() {
        return Result.success(detailService.make());
    }
}
